/// @Classname : HcEmpty
/// @Author :
/// @Time : 2023-07-19 16:00
/// @Description : //todo

import 'package:flutter/material.dart';
import 'package:hc_ui/config/hc_customer_config.dart';
import 'package:hc_ui/theme/hc_empty_theme.dart';

import 'package:hc_ui/widget/button_panel/hc_dialog_button_panel.dart';
import 'package:hc_ui/widget/image/hc_image.dart';

class HcEmpty extends StatelessWidget {
  // 主按钮文字
  final String? primaryBtnText;

  // 次级按钮文字
  final String? secondaryBtnText;

  // 自定义图片组件
  final Widget? image;

  // 自定义title组件
  final Widget? title;
  final MainAxisAlignment mainAxisAlignment;
  final VoidCallback? backgroundClick;

  // 自定义描述组件
  final Widget? description;
  final HcButtonType primaryBtnType;
  final HcButtonType secondaryBtnType;
  final bool primaryBtnDisabled;
  final VoidCallback? primaryBtnOnTap;
  final VoidCallback? secondaryBtnOnTap;
  final HcEmptyTheme? themeData;

  HcEmpty(
      {Widget? description,
      super.key,
      Widget? image,
      Widget? title,
      this.primaryBtnText,
      this.secondaryBtnText,
      this.primaryBtnType = HcButtonType.elevated,
      this.secondaryBtnType = HcButtonType.outlined,
      String? imageUlr,
      String? titleText,
      String? descriptionText,
      this.primaryBtnDisabled = false,
      this.primaryBtnOnTap,
      this.mainAxisAlignment = MainAxisAlignment.center,
      this.themeData,
      this.secondaryBtnOnTap,
      this.backgroundClick})
      : image = image ?? (imageUlr != null ? HcImage(src: imageUlr) : null),
        title = title ?? (titleText != null ? Text(titleText) : null),
        description = description ??
            (descriptionText != null ? Text(descriptionText) : null);

  @override
  Widget build(BuildContext context) {
    HcEmptyTheme theme = themeData ?? HcEmptyTheme();
    theme = HcCustomerConfig().allTheme.emptyTheme.merge(theme);
    return Container(
      color: theme.backgroundColor,
      width: double.infinity,
      padding: theme.padding,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisAlignment: mainAxisAlignment,
        mainAxisSize: MainAxisSize.max,
        children: [
          Column(
            children: [
              if (image != null)
                Container(
                  margin: theme.imageMargin,
                  padding: theme.imagePadding,
                  child: image,
                ),
              if (title != null)
                Container(
                  margin: theme.titleMargin,
                  padding: theme.titlePadding,
                  child: DefaultTextStyle(
                      style: theme.titleTextStyle, child: title!),
                ),
              if (description != null)
                Container(
                  margin: theme.descMargin,
                  padding: theme.descPadding,
                  child: DefaultTextStyle(
                      style: theme.descTextStyle, child: description!),
                ),
            ],
          ),
          if (primaryBtnText != null || secondaryBtnText != null)
            HcDialogButtonPanel(
              mainButtonText: primaryBtnText ?? secondaryBtnText ?? '',
              mainButtonOnTap: primaryBtnOnTap ?? () {},
              mainButtonDisabled: primaryBtnDisabled,
              buttonSpacing: theme.buttonSpacing,
              mainButtonType: primaryBtnType,
              padding: EdgeInsets.zero,
              secondaryButtonOnTap: (int index) {
                if (secondaryBtnOnTap != null) {
                  secondaryBtnOnTap!();
                }
              },
              secondaryButtonList:
                  secondaryBtnText != null && primaryBtnText != null
                      ? [HcButtonPanelConfig(label: secondaryBtnText!)]
                      : null,
            )
        ],
      ),
    );
  }
}
